#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QFile>
#include <QFileSelector>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQuickStyle::setStyle("Fusion");

    QQmlApplicationEngine engine;
    QFileSelector selector;
    QFile defaultsFile(selector.select("chapter4-3shared/Main.qml"));
    qDebug() << defaultsFile.fileName();

    if (defaultsFile.fileName().contains("+andriod"))
        QQuickStyle::setStyle("Material");

    const QUrl url(defaultsFile.fileName());
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
        &app, [&url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        },
        Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
